package com.example.test10mvc.socket;

import com.example.test10mvc.utils.RestResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: fxy
 * @Date: 2023/01/09/16:45
 * @Description:
 */
@RestController
public class AwebSocketTestController {

    @Resource
    private WebSocketServer webSocketServer;

    @ApiOperation(value = "实时报警")
    @GetMapping(value = "/data")
    public RestResult<String> realTimeAlarm() {
        return RestResult.success("11111111");
    }

    @Scheduled(cron = "0/3 * * * * ?")
    public void realTimeAlarm1() {
        if (!CollectionUtils.isEmpty(WebSocketServer.webSocketSet)) {
            // 查询待处理报警类

            webSocketServer.sendToMessageById("getAlarmCenterInfoInOneHour", "报警websocket测试");
        }
    }

}
